main(i,j,n,b,s)
{
	int a[3];
	for(gets(&i);~scanf("%d%d",&i,&j);printf("%dS %dB\n",s,b))
	{
		for(b=s=n=0;n<3;a[n++]=j%10,j/=10);

		for(;i;i/=10)
			for(j=0;j<3;j++)
				if(a[j]==i%10)
					2-(int)log10(i)==j?s++:b++;
	}
}
